/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-12 17:43:17
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-13 14:47:13
 */
/*
 * @Author: your name
 * @Date: 2021-07-26 15:30:11
 * @LastEditTime: 2021-07-29 14:50:49
 * @LastEditors: GGB
 * @Description: In User Settings Edit
 * @FilePath: \flutter_faster_study\lib\controller\controller.dart
 */

import 'package:flutter_data_center/model/home/attendance_model.dart';
import 'package:flutter_data_center/model/home/module_model.dart';
import 'package:flutter_data_center/model/home/school_moment_model.dart';
import 'package:flutter_data_center/model/home/task_model.dart';
import 'package:flutter_data_center/model/home/today_person_statistics_model.dart';
import 'package:flutter_data_center/model/module/module_statistics_module.dart';
import 'package:flutter_data_center/net/dio_utils.dart';
import 'package:get/get.dart';

class HomeController extends GetxController {
  // 今日统计
  TPStatisticsModel _todayStatistics =
      TPStatisticsModel(student: 0, teacher: 0, visiror: 0);
  TPStatisticsModel get todayStatistics => _todayStatistics;
  void getTPStatistics() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.TPStatistics,
    );
    if (responseInfo.success) {
      _todayStatistics = TPStatisticsModel.fromJson(responseInfo.data);
      update();
    }
  }

  // 考勤统计
  AttendanceModel _attendanceStatistics =
      AttendanceModel(student: 0, teacher: 0);
  AttendanceModel get attendanceStatistics => _attendanceStatistics;
  void getAttendanceStatistics() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.attendanceStatistics,
    );
    if (responseInfo.success) {
      _attendanceStatistics = AttendanceModel.fromJson(responseInfo.data);
      update();
    }
  }

  // 任务统计
  TaskModel _taskStatistics = TaskModel(total: 0, deal: 0);
  TaskModel get taskStatistics => _taskStatistics;
  void getTaskStatistics() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.taskStatistics,
    );
    if (responseInfo.success) {
      _taskStatistics = TaskModel.fromJson(responseInfo.data);
      update();
    }
  }

  // 菜单列表
  List<ModuleModel> _moduleList = [];
  List get moduleList => _moduleList;
  void getModules() async {
    _moduleList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.moduleList,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _moduleList.add(ModuleModel.fromJson((item)));
      }
      update();
    }
  }

  // 应用列表
  List<ModuleModel> _appList = [];
  List get appList => _appList;
  void getApp() async {
    _appList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.appList,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _appList.add(ModuleModel.fromJson((item)));
      }
      update();
    }
  }

  // 校园姿态
  List<SchoolMomentModel> _momentList = [];
  List get momentList => _momentList;
  void getSchoolMoments() async {
    _momentList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.schoolMoment,
    );

    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _momentList.add(SchoolMomentModel.fromJson((item)));
      }
      update();
    }
  }

  // 模块统计
  List<ModuleStatisticModel> _moduleStatisticsList = [];
  List<ModuleStatisticModel> get moduleStatisticsList => _moduleStatisticsList;
  void getModuleStatistics() async {
    _moduleStatisticsList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.moduleStatistics,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _moduleStatisticsList.add(ModuleStatisticModel.fromJson(item));
      }
      update();
    }
  }
}
